package tech.jabari.user.controller;

import tech.jabari.user.entity.User;
import tech.jabari.user.service.UserService;
import tech.jabari.user.service.impl.UserServiceImpl;
import tech.jabari.utils.JdbcUtil;
import tech.jabari.utils.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/userList.action")
public class UserListServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取用户提交的请求参数
        String pageNoStr = request.getParameter("pageNo");//页码
        String pageSizeStr = request.getParameter("pageSize");//每页记录数
        // 获取用户名参数的值
        String username = request.getParameter("username");
        Integer pageNo = Integer.parseInt(pageNoStr);
        Integer pageSize = Integer.parseInt(pageSizeStr);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("pageNo", pageNo);
        paramMap.put("pageSize", pageSize);
        paramMap.put("username", username);
        //将参数传给Service。
        String result = userService.selectAllUser(paramMap);
        //将结果展示给浏览器。
        response.getWriter().write(result);
    }
}
